import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView
  },
  {
    path: '/Order',
    name: 'order',
    component: () => import(/* webpackChunkName: "order" */ '../views/Order.vue')
  },
  {
    path: '/User',
    name: 'user',
    component: () => import(/* webpackChunkName: "user" */ '../views/User.vue'),
    redirect: "/user/cart",
    children: [
      {
        path: "cart",
        component: () => import(/* webpackChunkName: "user" */"../components/user/Cart.vue")
      }
    ]
  },
  {
    path: '/Goods',
    name: 'goods',
    component: () => import(/* webpackChunkName: "Goods" */ '../views/Goods.vue')
  },
  {
    path: '/Free',
    name: 'free',
    component: () => import(/* webpackChunkName: "Free" */ '../views/Free.vue')
  }
  // {
  //   path: '/about',
  //   name: 'about',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  // }
  ,
  {
    path: '/home',
    name: 'Home',
    component: () => import(/* webpackChunkName: "Home" */ '../views/Home.vue')
  },
  // 产品详情页
  {
    path: '/detail',
    name: 'Detail',
    component: () => import(/* webpackChunkName: "Detail" */ '../views/Detail.vue')
  },
  {
    path: "*",
    name: "Eroo",
    component: () => import(/* webpackChunkName: "Eroo" */ "../views/Eroo")
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router

// 把这段代码直接粘贴到router/index.js中的Vue.use(VueRouter)之前
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function (location) {
  return originalPush.call(this, location).catch(err => { })
};